<?php
	class ConfigManager
	{
		private static $config_filename =  '/hotel/common/config.xml';
		private static $xml_config;
		
		function __construct() {
			if(file_exists($_SERVER["DOCUMENT_ROOT"] . self::$config_filename)) {
				self::$xml_config = simplexml_load_file($_SERVER["DOCUMENT_ROOT"] . self::$config_filename);
			} else {
				print 'FATAL: Could not load configuration file.';
				die();
			}
		}
		
		//Function getInstance()
		//This function implements a 'Singleton' design pattern, use this to get the instance of the class
		//use as follows: $config = ConfigManager::getInstance();
		public static function getInstance() {
			static $instance;
			
			if(!isset($instance)) {
				$cls = __CLASS__;
				$instance = new $cls;
			}
			
			return $instance;
		}
		
		public function get_mysql_server() {
			$servername = self::$xml_config->xpath("database/server");
			return $servername[0];
		}
		
		public function get_mysql_user() {
			$user = self::$xml_config->xpath("database/user");
			return $user[0];
		}
		
		public function get_mysql_password() {
			$password = self::$xml_config->xpath("database/password");
			return $password[0];
		}
		
		public function get_mysql_catalog() {
			$database = self::$xml_config->xpath("database/catalog");
			return $database[0];
		}
	}
?>